﻿// Problem 25
// 
// What is the first term in the Fibonacci sequence to contain 1000 digits?
//
// correct answer is 4782

#light

open Microsoft.FSharp.Math

let fibonacci =
    let rec fibonacciInner (a:BigInt) (b:BigInt) =
        seq { let c = a + b   
              yield c  
              yield! fibonacciInner b c }
    seq { yield 1I  
          yield 1I  
          yield! fibonacciInner 1I 1I }  
          
let answerProblem (upto:BigInt) =
        ( fibonacci  
        |> Seq.takeWhile (fun (elem) -> elem < upto)   // The take_while stops one short
        |> Seq.length ) + 1                             // so increment result
        
let solve() = answerProblem (10I ** 999I)
